{include file='common/header' /}

<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <div class="layui-row">
                        <table class="layui-table" id="list" lay-filter="toolbarId"></table>
                    </div>
                </div>
            

            </div>
        </div>
    </div>
</div>


{include file="common/footer"/}
<script type="text/html" id="action">
    <div class="layui-btn-group">
        <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="recover">恢复</a>
        <a href="{:url('downFile')}?time={{d.time}}" class="layui-btn layui-btn-xs">下载</a>
        <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delfile">{:lang('del')}</a>
    </div>
</script>
<script type="text/html" id="time">
    {{layui.util.toDateString(d.time*1000, 'yyyy-MM-dd HH:mm:ss')}}
</script>
<script>
var table;
    layui.use('table', function() {
        table = layui.table;
        table.render({
            elem: '#list'
            ,url: '{:url("restore")}',
            method:'post'
            ,cols: [[
                {field:'filename', title: '文件名称', width:250},
                {field:'size', title: '文件大小', width:200,sort:true},
                {field:'time', title: '备份时间', width:200,sort:true,templet: '#time'},
                {title:'操作',minWidth:150, toolbar: '#action',align:"center"} ,           ]]
        });
        table.on('tool(toolbarId)', function(obj) {
            var data = obj.data;

            if (obj.event === 'recover') {
                layer.confirm('确认要导入数据吗？',{icon: 0}, function (index) {
                    loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post("{:url('import')}",{time:data.time},function(res){
                        layer.close(loading);
                        if(res.code>0){
                            layer.msg(res.msg, {time: 1000,icon:1});
                        }else{
                            layer.msg(res.msg, {time: 1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }else if(obj.event === 'delfile'){
                layer.confirm('确认要删除该备份文件吗？', {icon: 3}, function (index) {
                    loading = layer.load(1, {shade: [0.1, '#fff']});
                    $.post('{:url("delSqlFiles")}',{time: data.time}, function (res) {
                        layer.close(loading);
                        if (res.code > 0) {
                            layer.msg(res.msg, {time: 1000,icon:1});
                            obj.del();
                        }else{
                            layer.msg(res.msg,{time: 1000,icon:2});
                        }
                    });
                    layer.close(index);
                });
            }
        });
    });
</script>